package com.alibaba.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * @Author: zhuangzhiwen
 * @Date: 2021/8/22
 */
@Demo(className = "com.alibaba.annotation.Person", methodName = "show")
public class ReflectTest2 {
    public static void main(String[] args) throws Exception {
        Class c1 = Class.forName("com.alibaba.annotation.ReflectTest2");
        if (c1.isAnnotationPresent(Demo.class)) {
            Demo demo = (Demo) c1.getAnnotation(Demo.class);
            String className = demo.className();
            String methodName = demo.methodName();
            Class c2 = Class.forName(className);
            Object object = c2.newInstance();
            Method method = c2.getMethod(methodName);
            method.invoke(object);
        }
    }
}
